package com.example.finaltask;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.finaltask.modle.User;
import com.example.finaltask.utils.Remove;
import com.example.finaltask.utils.RoundImageView;

import java.io.File;

public class ExitActivity extends AppCompatActivity {
    private TextView nickname;
    private Button logout,login;
    private RoundImageView headImage;
    private User user;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exit);
        Remove.removeTop(this);
        init();
        listeners();
    }

    /**
     *@description 初始化
     */
    private void init(){
        headImage = findViewById(R.id.userInfo_headImage);
        logout = findViewById(R.id.logout);
        login = findViewById(R.id.login);
        nickname = findViewById(R.id.nickname);
        Intent intent = this.getIntent();
        user = (User) intent.getSerializableExtra("user");
        //用户头像
        if(user==null){
            Glide.with(this).load("https://img.zcool.cn/community/016efd56e823f032f875520f84f543.jpg@1280w_1l_2o_100sh.jpg").into(headImage);
            login.setVisibility(View.VISIBLE);
        }else{
            Glide.with(this).load(user.getHeadImage()).into(headImage);
            nickname.setText(user.getUserName());
            logout.setVisibility(View.VISIBLE);
        }
    }

    /**
     *@description 监听器
     */
    @SuppressLint("ClickableViewAccessibility")
    private void listeners(){
                logout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //跳转信息页面,传递对象
                        Intent intent = new Intent();
                        intent.setClass(ExitActivity.this, MainActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("user", user);
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }
                });
            }
        }